home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Cosmo Software 1997 May
/
SGI Cosmo Software 1997 May.iso
/
dist
/
netscape.idb
/
usr
/
local
/
lib
/
netscape
/
conv_alias.z
/
conv_alias
Wrap
Text File
|
1997-05-23
|
9KB
|
236 lines
#!/bin/sh
# This shell script reads $HOME/.zmailrc and converts aliases found to
# an html file understood by Netscape's Address Book (version 2.x and
# above).
# 07/11/96 A.T. - Created.
# 09/06/96 A.T. - Fixed to correctly parse email addresses in the
# format of "john@sgi.com (John Smith)".
PATH=/usr/sbin:/usr/bsd:/sbin:/usr/bin:/bin:/usr/bin/X11
TDIR=/usr/tmp
ZMAILRC=$HOME/.zmailrc
ADDR_BOOK=$HOME/.netscape/address-book.html
ADDR_BOOK_USER=$TDIR/.addr_book_user.$$
ADDR_BOOK_LIST=$TDIR/.addr_book_list.$$
MMAIL_ALIAS=$TDIR/.mmail_alias.$$
MMAIL_LIST=$TDIR/.mmail_list.$$
MMAIL_LIST2=$TDIR/.mmail_list2.$$
NEW_ADDR_BOOK=$TDIR/.new_addr_book.$$
NEW_USER=$TDIR/.new_user.$$
NEW_LIST=$TDIR/.new_list.$$
FINAL=$TDIR/.final.$$
# If there's no MediaMail .zmailrc file, there's nothing to do.
if [ ! -f "$ZMAILRC" ]; then
echo "$ZMAILRC file does not exist."
exit
fi
# Create $HOME/.netscape directory if one doesn't exist.
if [ ! -d "$HOME/.netscape" ]; then
mkdir $HOME/.netscape
fi
# This script should run when netscape is not running. Check this.
if [ -l "$HOME/.netscape/lock" ]; then
echo "\n***IMPORTANT: This script should run when netscape is not running.\n***Please quit netscape and hit return to continue.\c"
read ANS
echo
fi
# Backup original address book.
#
# Netscape doesn't automatically assign alias ids to all users and lists.
# Just in case there is a MediaMail alias that should reference existing
# Netscape users/lists, the following will assign alias ids to users and
# lists that don't have one.
#
# Build temporary files of users and lists from address book.
if [ -f "${ADDR_BOOK}" ]; then
if [ -f "${ADDR_BOOK}.original" ]; then
cp ${ADDR_BOOK} ${ADDR_BOOK}.$$
else
cp ${ADDR_BOOK} ${ADDR_BOOK}.original
fi
nawk -F'"' 'BEGIN { AC=10000 }
{ if ( $1 ~ "A HREF" && $3 ~ "NICKNAME" )
{ AC=AC+1;
printf ("%s\"%s\" ALIASID=\"%s\"%s\"%s\"%s\n", $1, $2, AC, $3, $4, $5);
}
else if ( $1 ~ "H3 " && $0 !~ "ALIASID" && $0 !~ "ALIASOF" )
{ AC=AC+1;
printf (" <DT><H3 ALIASID=\"%s\" NICKNAME=\"%s\"%s\n", AC, $2, $3);
}
else
print $0;
}' < $ADDR_BOOK > $NEW_ADDR_BOOK
sed -n 's/.*A HREF="\(.*\)" ALIASID\(.*\) NICKNAME="\(.*\)">\(.*\)<.*/\3\|\4|\1|\2/p' < $NEW_ADDR_BOOK > $ADDR_BOOK_USER
sed -n 's/.*H3 ALIASID\(.*\) NICKNAME="\(.*\)".*/\2|\1/p' < $NEW_ADDR_BOOK > $ADDR_BOOK_LIST
else
touch $ADDR_BOOK_USER $ADDR_BOOK_LIST $NEW_ADDR_BOOK
fi
# Build temporary files of aliases and mailing lists from MediaMail's .zmailrc
# file.
sed -n 's/^ *alias *\([^ ]*\) *\(.*\)/\1|\2/p' $ZMAILRC | grep -v "," | tr -d "'" | tr -d '"' > $MMAIL_ALIAS
sed -n 's/^ *alias *\([^ ]*\) *\(.*\)/\1|\2/p' $ZMAILRC | grep "," | tr -d "'" | tr -d '"' > $MMAIL_LIST
# Process MediaMail users file first. If user is not already in address book,
# add user to the user temp html file. If address is a mailing list, skip it
# for now by adding it to the lists file. Netscape requires that nickname
# contains only lowercase characters, numbers or "_", so there may be a
# slight translation of the alias name. If the address is in the format
# of "John Smith <john@sgi.com>" or "john@sgi.com (John Smith)", then the
# Name field will be John Smith. Otherwise, it will be the same as the alias
# name.
ALIAS_COUNT=20000
while read LINE
do
NICKNAME=`echo $LINE | cut -d"|" -f1 | tr '[A-Z]' '[a-z]' | tr "\!@#$%^&\*()-+={}\[\]|\:;<>,.?/ " "[_*]"`
NAME="$NICKNAME"
ADDR=`echo $LINE | cut -d"|" -f2`
if [ -z "`grep \"^${NICKNAME}\|\" $ADDR_BOOK_USER`" ]; then
if [ -z "`grep \"^${ADDR}\|\" $ADDR_BOOK_LIST $MMAIL_LIST`" ]; then
ALIAS_COUNT=`expr $ALIAS_COUNT + 1`
if [ -n "`echo $ADDR | grep '<'`" ]; then
NAME=`echo $ADDR | sed -n 's/\(.*\) <\(.*\)>/\1/p'`
ADDR=`echo $ADDR | sed -n 's/\(.*\) <\(.*\)>/\2/p'`
if [ -z "$NAME" ]; then
NAME="$NICKNAME"
fi
elif [ -n "`echo $ADDR | grep '('`" ]; then
NAME=`echo $ADDR | sed -n 's/\(.*\) (\(.*\))/\2/p'`
ADDR=`echo $ADDR | sed -n 's/\(.*\) (\(.*\))/\1/p'`
if [ -z "$NAME" ]; then
NAME="$NICKNAME"
fi
fi
echo " <DT><A HREF=\"mailto:${ADDR}\" ALIASID=\"$ALIAS_COUNT\" NICKNAME=\"$NICKNAME\">$NAME</A>" >> $NEW_USER
echo "$NICKNAME|$NAME|mailto:$ADDR|=\"$ALIAS_COUNT\"" >> $ADDR_BOOK_USER
else
echo $LINE >> $MMAIL_LIST
fi
else
echo "Alias $NICKNAME not added because it exists in the Address Book already."
fi
done < $MMAIL_ALIAS
# Assign alias ids to the MediaMail lists file. Have to do this first because
# lists can reference other lists.
nawk 'BEGIN { AC=30000 }
{ AC=AC+1;
printf ("%s|=\"%s\"\n", $0, AC);
}' < $MMAIL_LIST > $MMAIL_LIST2
# Process MediaMail lists file now. If list is not already in address book,
# get the alias id for the list and add list to the list temp html file.
# For each address in the list, determine whether it is a user or list.
# If user/list is not already in address book, add user/list to the appropriate
# temp html file. If user/list is in the address book, find its alias id
# and reference it in the list temp html file.
ALIAS_COUNT=40000
while read LINE
do
ORIG_NICKNAME=`echo $LINE | cut -d"|" -f1`
NICKNAME=`echo $LINE | cut -d"|" -f1 | tr '[A-Z]' '[a-z]' | tr "\!@#$%^&\*()-+={}\[\]|\:;<>,.?/ " "[_*]"`
if [ -z "`grep \"^${NICKNAME}\|\" $ADDR_BOOK_LIST`" ]; then
ALIASID=`grep "^${ORIG_NICKNAME}\|" $MMAIL_LIST2 | cut -d"|" -f3`
echo " <DT><H3 ALIASID$ALIASID NICKNAME=\"$NICKNAME\">$NICKNAME</H3>" >> $NEW_LIST
echo " <DL><p>" >> $NEW_LIST
echo "$NICKNAME|$ALIASID" >> $ADDR_BOOK_LIST
NBR_ADDR=`echo $LINE | awk -F, '{print NF}'`
ALL_ADDR=`echo $LINE | cut -d"|" -f2`
ADDR_INDEX=1
while [ $ADDR_INDEX -le $NBR_ADDR ]
do
ADDR=`echo $ALL_ADDR | cut -d, -f$ADDR_INDEX`
ADDR=`echo $ADDR`
NAME=""
if [ -n "`echo $ADDR | grep '<'`" ]; then
NAME=`echo $ADDR | sed -n 's/\(.*\) <\(.*\)>/\1/p'`
ADDR=`echo $ADDR | sed -n 's/\(.*\) <\(.*\)>/\2/p'`
elif [ -n "`echo $ADDR | grep '('`" ]; then
NAME=`echo $ADDR | sed -n 's/\(.*\) (\(.*\))/\2/p'`
ADDR=`echo $ADDR | sed -n 's/\(.*\) (\(.*\))/\1/p'`
fi
if [ -n "$NAME" ]; then
NNAME=`echo $NAME | tr '[A-Z]' '[a-z]' | tr "\!@#$%^&\*()-+={}\[\]|\:;<>,.?/ " "[_*]"`
else
NAME="$ADDR"
NNAME=`echo $ADDR | tr '[A-Z]' '[a-z]' | tr "\!@#$%^&\*()-+={}\[\]|\:;<>,.?/ " "[_*]"`
fi
if [ -z "`grep \"^${NNAME}\|\" $ADDR_BOOK_USER`" ]; then
if [ -z "`grep \"^${NNAME}\|\" $ADDR_BOOK_LIST`" -a -z "`grep \"^${NAME}\|\" $MMAIL_LIST2`" ]; then
ALIASOF=`grep "mailto:${ADDR}\|" $ADDR_BOOK_USER | cut -d"|" -f4`
if [ -z "$ALIASOF" ]; then
ALIAS_COUNT=`expr $ALIAS_COUNT + 1`
echo " <DT><A HREF=\"mailto:${ADDR}\" ALIASID=\"$ALIAS_COUNT\" NICKNAME=\"$NNAME\">$NAME</A>" >> $NEW_USER
echo "$NNAME|$NAME|mailto:$ADDR|=\"$ALIAS_COUNT\"" >> $ADDR_BOOK_USER
ALIASOF="=\"$ALIAS_COUNT\""
echo " <DT><A HREF=\"mailto:${ADDR}\" ALIASOF${ALIASOF}></A>" >> $NEW_LIST
else
echo " <DT><A HREF=\"mailto:${ADDR}\" ALIASOF${ALIASOF}></A>" >> $NEW_LIST
fi
else
ALIASOF=`grep "^${NNAME}\|" $ADDR_BOOK_LIST | cut -d"|" -f2`
if [ -z "$ALIASOF" ]; then
ALIASOF=`grep "^${NNAME}\|" $MMAIL_LIST2 | cut -d"|" -f3`
fi
echo " <DT><H3 ALIASOF${ALIASOF}></H3>" >> $NEW_LIST
fi
else
ALIASOF=`grep "^${NNAME}\|" $ADDR_BOOK_USER | cut -d"|" -f4`
echo " <DT><A HREF=\"mailto:${ADDR}\" ALIASOF${ALIASOF}></A>" >> $NEW_LIST
fi
ADDR_INDEX=`expr $ADDR_INDEX + 1`
done
echo " </DL><p>" >> $NEW_LIST
else
echo "Alias $NICKNAME not added because it exists in the Address Book already."
fi
done < $MMAIL_LIST
# Concatenate the new user and new list files to address book.
cat $NEW_ADDR_BOOK > $FINAL
echo "<DL><p>" >> $FINAL
cat $NEW_USER $NEW_LIST 2>/dev/null >> $FINAL
echo "</DL><p>" >> $FINAL
cp $FINAL $ADDR_BOOK
# Clean up.
rm -f $ADDR_BOOK_USER $ADDR_BOOK_LIST $MMAIL_ALIAS $MMAIL_LIST $MMAIL_LIST2 $NEW_ADDR_BOOK $NEW_USER $NEW_LIST $FINAL 2>/dev/null
echo "\nAlias conversion completed.\n"